package com.fengkai.filepost.pdfoutstream.test.ODsolutions;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author Fengkai
 * 第一行输入newspaper内容，包括1-N个字符串，用空格分开
 * 第二行输入anonymousLetter内容，包括1-N个字符串，用空格分开
 * @creat 2023/4/2
 */
public class AnonymousLetter {

    public static void main (String[] args) {
        System.out.println(myMethod("ab bcd ef", "ef fe"));
        int a = 'a';
        int b = 'b';
        int c = 'e';
        int d = 'f';
        System.out.println(Integer.toBinaryString(a));
        System.out.println(Integer.toBinaryString(b));
        System.out.println(Integer.toBinaryString(c));
        System.out.println(Integer.toBinaryString(d));
        System.out.println(97 ^ 98 ^ 101 ^ 102);

    }

    public static boolean myMethod (String newspaper, String anonymousLetter) {
        List<String> newspapers = getSortList(newspaper);
        List<String> anonymousLetters = getSortList(anonymousLetter);
        int count = 0; //匹配到的数量
        boolean dp[] = new boolean[newspapers.size()]; //是否使用过
        out:
        for (int i = 0; i < anonymousLetters.size(); i++) {
            for (int j = 0; j < newspapers.size(); j++) {
                if (!dp[j]) {
                    if (newspapers.get(j).equals(anonymousLetters.get(i))) {
                        count++;
                        dp[j] = true;
                        continue out;
                    }
                }
            }
        }
        return count == anonymousLetters.size();
    }

    //
    private static List<String> getSortList (String str) {
        String[] strings = str.split(" ");
        ArrayList<String> list = new ArrayList<>();
        for (String s : strings) {
            char[] chars = s.toCharArray();
            Arrays.sort(chars);
            list.add(new String(chars));
        }
        return list;
    }

    int checkInt (String str) {
        int res = 0;
        char[] chars = str.toCharArray();
        for (char aChar : chars) {
            res ^= aChar;
        }
        return res;
    }
}

